#include "AdminAddNewFoodWindow.h"
#include "ui_AdminAddNewFoodWindow.h"

AdminAddNewFoodWindow::AdminAddNewFoodWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AdminAddNewFoodWindow)
{
    ui->setupUi(this);
    this->setWindowTitle("添加食物");   //设置标题
}

AdminAddNewFoodWindow::~AdminAddNewFoodWindow()
{
    delete ui;
}

//显示添加食物界面
void AdminAddNewFoodWindow::replyShowAdminAddNewFoodWindow(){
    this->show();
}

//添加食物
void AdminAddNewFoodWindow::on_add_btn_clicked(){
    FoodTable food_table;   //操作表food_table
    /**
     * @leiteorz
     * 从ui中加载食物实体
     */
    Food food;
    food.name = ui->name_et->toPlainText();
    food.price = ui->price_et->toPlainText().toInt();
    food.content = ui->content_et->toPlainText();
    food.is_null = 0;
    //插入表food_table中
    food_table.insertFood(food);
    //发送信号通知订餐列表数据改变
    emit broadcast_data_changed();
    //关闭窗口
    this->hide();
}
